我有一个针对我的iOS应用程序的自定义URL方案,我希望能够通过电子邮件发送给某人的链接,如果它在设备上,则启动应用程序,或者如果他们没有,则将其带到应用程序商店.
我希望能够发送myapp:// someurl并在appstore上启动或转到myapp,但我认为这不会开箱即用.
相反,我正在考虑创建一个链接,加载一些javascript,它将尝试myapp:// someurl,如果失败将改为加载应用商店链接.
我的javascript知识很糟糕.我可以设置window.location来执行重定向,但似乎没有办法从中捕获错误,以便在失败时执行另一个操作.
有人知道怎么做吗?
我需要在ajax调用成功时重新加载页面.
我看到了一些代码(不是我的代码),有两种方法:
success : function(obj) {
//code
location.href = location.href;
}
Run Code Online (Sandbox Code Playgroud)
要么
success : function(obj) {
//code
window.location.reload(true);
}
Run Code Online (Sandbox Code Playgroud)
这种行为有什么不同吗?我知道位置和window.location的区别,但在工作方面?
我试图通过UIWebView的shouldStartLoadWithRequest方法将多个内容从UIWebView内的网页传回我的iPhone应用程序.
基本上我的网页调用window.location.href ="command:// foo = bar",我能够拦截在我的应用程序中没问题.现在,如果我创建一个循环并立即执行多个window.location.href调用,那么shouldStartLoadWithRequest似乎只会被调用一次,并且它获得的调用是循环结束时window.location.href的最后一次触发.
Android的webview也会发生同样的事情,只会处理最后一个window.location.href.
您好我正在尝试使用PhoneGap为iPad开发应用程序.我想在index.html页面内部加载外部网站的主页面.不幸使用
window.location.href = "http://mywebsite.com/cgi-bin/index.py"
Run Code Online (Sandbox Code Playgroud)
触发打开Safari窗口而不是使用PhoneGap容器.
有什么建议?
非常感谢
克劳斯
下面的代码效果很好.这是我的问题:窗口网址重定向,但原始网址未记录在我的浏览器历史记录中.
例如,如果我访问"http://example.com/page1",浏览器就会重定向到"http://example.com/test".但是,我需要访问的原始网址("http://example.com/page1")显示在我的浏览器历史记录中,以便我可以在其他功能中调用它.
在重定向之前,是否有访问原始网址以登录浏览器的历史记录?
<!-- script to enable age verification cookies and ensure people have age checked -->
<script type="text/javascript">
$(document).ready(function(){
if (window.location =="http://example.com/home") {//do nothing
} else {
window.location = "http://example.com/test";
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 我在ajax调用之后使用JavaScript重定向(在更新内容之后).我试过以下方法,都很慢.在"网络"选项卡中,它显示等待时间约为4.44到5秒.(这对客户来说非常令人沮丧:()
window.location.assign(to_redirect);
window.location.replace(to_redirect);
location.href= to_redirect;
window.location.href= to_redirect;
window.location = to_redirect;
Run Code Online (Sandbox Code Playgroud)
W¯¯从网页浏览往往微不足道网站页面(用鼠标点击)它的等待时间是350毫秒到450ms.
为什么会这样 ?有什么我错过的或任何其他方式更快?
根据评论者的要求,下面是截图.
我们使用window.location.href将用户导航到页面.此外,我们已配置window.onbeforeunload事件,以便在存在任何未保存的更改时提醒用户.
window.onbeforeunload = confirmBeforeClose;
function confirmBeforeClose() {
if (jwd.global.inEditMode)
return "Your changes will not be saved :) and you will be punished to death";
}
Run Code Online (Sandbox Code Playgroud)
在有未保存更改的地方,我尝试使用window.location.href导航用户,我收到警报消息.
如果我在弹出窗口中单击"确定",它可以正常工作.但是,如果我单击CANCEL,JS会在window.location.href处抛出一个未指定的错误.
任何帮助表示赞赏.
如何检查对window.location的调用是否失败,因为给定的URL无效等?是否有一些事件可以设置在窗口对象或其他可以捕获它的对象上?
这个问题与window.location = window.location作为刷新页面方法的代码有关,与重定向/其他变量无关。
我的理解如下:
window.location = window.location 导致页面刷新,因为浏览器将导航到用户已经所在的位置。
通过 DOM 操作对该变量的任何更改都将导致页面重新加载/加载攻击者页面,因此这些行将无法以更改的值执行,因此不是跨站点脚本攻击的候选者。
这样对吗?
编辑:我真正要问的是是否有一种方法可以在window.location不导致页面重新加载的情况下进行更改,以便在进行window.location = window.location调用时,浏览器将被发送到另一个位置。
我在构建 nextjs 应用程序时收到以下错误。尽管我只使用 js,但出于构建原因,我的 nextjs 应用程序配置了 typecipt。
Build error occurred:
TypeError: Cannot destructure property 'protocol' of 'window.location' as it is undefined.
at getLocationOrigin (/var/www/tradersnode/html/tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/utils.js:3:162)
at Object.<anonymous> (/var/www/tradersnode/html/tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/router/utils/parse-relative-url.js:1:206)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/var/www/tradersnode/html/tradersnode/client/mpanel/node_modules/next/dist/next-server/lib/router/router.js:1:558)
at Module._compile (internal/modules/cjs/loader.js:1156:30) {
type: 'TypeError'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run Code Online (Sandbox Code Playgroud)
这是我的 tsconfig.json 文件:
{
"compilerOptions": {
"target": "es5",
"lib": [ …Run Code Online (Sandbox Code Playgroud) window.location ×10
javascript ×8
redirect ×3
browser ×1
build ×1
cordova ×1
html ×1
ios ×1
ipad ×1
iphone ×1
jquery ×1
next.js ×1
reload ×1
typescript ×1
uiwebview ×1
url-scheme ×1
xss ×1