我想获取位置和第一个文件夹,如:
http://www.example.com/test/
var $location = window.location.href;
alert ($location);
Run Code Online (Sandbox Code Playgroud)
这回来了
http://www.example.com/test/location-test.html
Run Code Online (Sandbox Code Playgroud)
所以我希望它能将所有内容归还为"test /",所以我最终只能:
http://www.example.com/test/
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在尝试window.location使用Greasemonkey在文档的开头有选择地禁用它.
我不想完全禁用javascript,只是禁用一些使用javascript完成的重定向.它们看起来像这样:
window.location = "unwanted url";
Run Code Online (Sandbox Code Playgroud) 出于某种原因,这适用于IE和Chrome,但不适用于Safari和Firefox.
$location.path(lastPath);
$window.location.reload(true);
Run Code Online (Sandbox Code Playgroud)
不重新加载最后一个路径,而是重新加载$window.location.reload(true)当前页面.在Chrome中IE的重新加载发生在角度发生之后$location.path(lastPath).
我正在构建一个基本的AngularJS登录页面,$ window.location.href没有将页面重定向到我的系统中由WAMP托管的新html.我甚至尝试将它重新指向谷歌.什么都没发生.我在这里尝试了所有可用的解决方案,似乎没有任何效果.有解决方案吗
JS后跟HTML
var app = angular.module('myApp', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.submit = function() {
if ($scope.username && $scope.password) {
var user = $scope.username;
var pass = $scope.password;
if (pass == "admin" && user == "admin@admin.com") {
alert("Login Successful");
$window.location.href = "http://google.com"; //Re-direction to some page
} else if (user != "admin@admin.com") {
alert("Invalid username");
} else if (pass != "admin" && user == "admin@admin.com") {
alert("Invalid password");
}
} else {
alert("Invalid …Run Code Online (Sandbox Code Playgroud)我有一个Html页面index.htm,它有一个iframe来搜索search.htm,search.htm有这样的代码
function executeSearch() {
window.parent.location = "/SearchResults.aspx?t=" + txt_Search.value;
}
Run Code Online (Sandbox Code Playgroud)
这个代码现在从index.htm页面执行,它在IE和Chrome上运行得很好,但不是FireFox ......有什么工作吗?我试过window.parent.location.href,window.opener.location,window.parent.document.location ......但是没有任何工作.
在搜索网页后,我发现了一个有类似问题的人,他说这是Firefox中的安全设置......这是真的吗?若有,有什么办法吗?
我的网站位于http://visualise.ca/,当您点击缩略图加载帖子时,它将使用ajax加载页面中的帖子.关闭帖子时,它使用此代码,以便在不重新加载页面的情况下将网址更改回http://visualise.ca/:
$("#close").live("click", function(event) {
$("#board").fadeOut("slow");
$("#board-wrapper").slideUp("slow");
$("html,body").delay(1000).animate({scrollTop: 0}, 300);
window.location.hash = "";
window.history.pushState(null,null,site_url+"/");
return false;
});
Run Code Online (Sandbox Code Playgroud)
但在IE8中,它将其更改为http://visualise.ca/#而不是http://visualise.ca/.有没有办法纠正这个并确保它改为http://visualise.ca/?
我想将用户从不同的URL重定向到特定的URL.我尝试了各种各样的替换方式,似乎无法得到我想要的行为.除了我提供主机名外,此代码有效.我想使用windows.location.hostname中的现有主机名,只提供一个新的路径名.有时网址大小和斜线('/')不同.
window.location = 'http://localhost:36065/NewPath';
Run Code Online (Sandbox Code Playgroud)
我该如何更改这些网址?
http://somesite.com/xxx/yyy/zzz to http://somesite.com/NewPath
http://somesite.com/xxx/yyy to http://somesite.com/NewPath
http://somesite.com/xxx to http://somesite.com/NewPath
Run Code Online (Sandbox Code Playgroud)
我认为你说对了.路径可以在路径上变化,我想在.com之后基本上用'NewPath'替换所有内容
如果可能的话,我想要一个干净的正则表达式解决方案,但我是那个部门的新手.感谢任何提示或技巧.
由于某种原因,下面的代码在尝试重定向时不起作用.我尝试过其他几种方法,比如window.location.href等等.唯一有效的是,window.open ("")但是当我需要它在同一个窗口时,这会在新窗口中打开一个页面.如果我window.open("", "_self")那么它再也不起作用了.如果我更换window.location用alert它工作得很好,所以我觉得整体的代码是正常的只是一些防止它在同一页上重定向.此问题也出现在我的Windows Chrome和Mac Firefox上.
<html>
<head>
<script type="text/javascript">
function checkAnswers(){
getElementById("myQuiz");
if(myQuiz.elements[1].checked){
window.location = "www.google.com";
}else{
alert("Failed");
}
};
</script>
</head>
<body>
<img src="Castle.JPG" />
<form id="myQuiz" onsubmit="checkAnswers()" action="">
<p>Name the country this castle is located in?
<br/>
<input type="radio" name="radiobutton" value="A"/>
<label>England</label>
<input type="radio" name="radiobutton" value="B"/>
<label>Ireland</label>
<input type="radio" name="radiobutton" value="C"/>
<label>Spain</label>
<input type="radio" name="radiobutton" value="D"/>
<label>France</label>
<input type="submit" name="submit" value="Submit"/>
<input type="reset" name="reset" value="Reset"/>
</p>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有这个功能我需要测试:
login(): void {
this.userService.setSessionAndDateOnlogin();
this.loginService.getLogin()
.subscribe(
octopusUrl => window.location.href = octopusUrl);
}
Run Code Online (Sandbox Code Playgroud)
我使用window.location.href导航到外部URL.
这是我的测试:
it('login function should call the setSessionAndDateOnLogin function from the userservice and\
subscribe to the getLogin function of the loginService.',
fakeAsync(
inject(
[LoginComponent, LoginService, UserService],
(loginComponent: LoginComponent, loginService: LoginService, userService: UserService) => {
spyOn(userService, 'setSessionAndDateOnlogin');
loginComponent.login();
expect(userService.setSessionAndDateOnlogin).toHaveBeenCalled();
})
)
);
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,我收到以下错误:
你的一些测试做了整页重装!
所以我试着模仿窗口对象:
import { window } from '@angular/platform-browser/src/facade/browser';
...
class MockWindow {
location: {
href: ''
};
}
...
beforeEach(() => addProviders([
...
{ provide: …Run Code Online (Sandbox Code Playgroud) 我有代码片段,点击链接执行,如下所示
cj_redirecturl="/HomeWork/main/load_course";
utility.xhttprw.data(cj_redirecturl,{data:courseid},function(response){
if(response){
window.location.href=base_url+"main";
///next
utility.xhttprw.data(redirecturl,{data:""},function(response){
if(response){
id=ent;
document.getElementById('content').innerHTML=response;
// Assignemnt module
//Call function from javascript/assignment.js file to display particular assignment (ent:means assignment_id) //
if(con==5)
{
get_assignment_id(ent);
}
if(con==9)
{
get_content_details(ent);
}
} //end of response
},false,false,false,'POST','html',true);
}
},false,false,false,'POST','html');
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,window.location.href=base_url+"main";将页面重定向到其各自的页面,但这会停止执行紧挨着它编写的代码.现在我希望这个代码在写入时执行,即首先代码应该带我到相应的"主"页面,然后代码写入后必须执行并给我一个必需的输出.
有人可以指导我实现这一目标吗?
window.location ×10
javascript ×4
jquery ×3
angularjs ×2
redirect ×2
angular ×1
firefox ×1
function ×1
greasemonkey ×1
hash ×1
hostname ×1
html ×1
jasmine ×1
login ×1
prototype ×1
regex ×1
unit-testing ×1