URL 参数阻止 javascript 正常工作?
首先,我的整个网站运行良好。到目前为止,所有页面都没有 URL 参数。现在问题开始了。我有一个 Flash 横幅,在 Apple 移动设备上必须是 PNG 静态图像。它工作得很好,直到我创建一个带有参数的页面(例如:mysite.com/Controller1/Page1/1)。一旦我有了参数,两个横幅(flash 和 PNG)都会出现。
这是我的 iOS.js:
if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))
{
alert("This was called - Mac mobile devices");
document.write('<style type="text/css"><!--#swf{display:none;}--></style>');
}
else {
alert("This was called - PC");
document.write('<style type="text/css"><!--#no-swf{display:none;}--></style><script src="js/swfobject_modified.js" type="text/javascript"></script>');
}
这是我的部分视图标题的摘要(刚刚从 _Layout 中提取,其行为是相同的):
@Html.JsScript("../../Scripts/iOS.js")
<div id="swf">
MY FLASH BANNER
</div>
<div id="no-swf">
MY STATIC IMAGE
</div>
当我尝试普通页面(无参数)时,我总是有消息框 This was called - PC
但是当我添加参数时(即使在同一页面上!),我没有收到任何消息。
也许这是一个路由问题?我最大限度地简化,只留下一条路线:
routes.MapRoute(
null, // Nom d'itinéraire
"{controller}/{action}/{id}", // URL avec des paramètres
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Paramètres par défaut
);
知道发生了什么吗?
First of all, my whole web site works fine. All the pages, up to now, have no URL parameter. Now the problem begins. I have a flash banner that has to be a PNG static image on Apple mobile devices. It works great until I create a page with a parameter (ex: mysite.com/Controller1/Page1/1). As soon as I have a parameter, both banners (flash and PNG) appear.
Here's my iOS.js:
if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i))
{
alert("This was called - Mac mobile devices");
document.write('<style type="text/css"><!--#swf{display:none;}--></style>');
}
else {
alert("This was called - PC");
document.write('<style type="text/css"><!--#no-swf{display:none;}--></style><script src="js/swfobject_modified.js" type="text/javascript"></script>');
}
Here's the summary of my partial view Header (just extracted from _Layout where the behavior was the same):
@Html.JsScript("../../Scripts/iOS.js")
<div id="swf">
MY FLASH BANNER
</div>
<div id="no-swf">
MY STATIC IMAGE
</div>
When I try a normal page (no parameter), I always have the message box This was called - PC
but when I add a parameter (even on the same page!), I don't get any message.
Maybe it is a routing problem? I simplified to the maximum to leave only one route:
routes.MapRoute(
null, // Nom d'itinéraire
"{controller}/{action}/{id}", // URL avec des paramètres
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Paramètres par défaut
);
Any idea of what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您向路径添加元素时,您需要向相对 URL 添加
../
或使用
确保相对 URL 解析为相同的绝对 URL。也许上面应该变成
或者您可以添加
到页面顶部附近。
http://www.w3.org/TR/html4/ struct/links.html#h-12.4 说
When you add an element to the path, you need to add a
../
to your relative URLs or use a<base href="...">
to make sure the relative URLs resolve to the same absolute URL.Maybe the above should become
or you can add
near the top of your page.
http://www.w3.org/TR/html4/struct/links.html#h-12.4 says