由于网站出现问题,我必须对页面上的所有链接使用 JavaScript。
就像这样...
<a href="javascript:this.location = 'stamping.html'"><img src="image.png"/></a>
网页上有很多带有 javascript 的链接会显着减慢速度吗?
JavaScript 是在页面最初加载时运行还是仅在单击链接时运行?
编辑:对于那些问我为什么这样做的人。我正在创建一个 iPad 网站,当您使用“添加到主页”按钮将网站添加为图标时,它允许用户在没有地址栏的情况下查看该网站。
然而,每次单击链接时,它都会在新窗口中重新打开 Safari,并返回地址栏。
我能找到的唯一解决方案是使用 javascript 而不是基于 html 的链接来打开页面。
有关进一步参考,请参阅...
iPad WebApp 在 Safari 中全屏
第二个答案
“它只会全屏打开第一个(已添加书签的)页面。任何下一页都将再次打开,并且地址栏将再次可见。”
第三个答案向下
“如果您想留在浏览器中。无需启动新的窗口使用以下 HTML 代码:
a href="javascript:this.location = 'index.php?page=1'"
“
Due to an issue that came up with a website I have to use javascript for all of the links on the page.
like so...
<a href="javascript:this.location = 'stamping.html'"><img src="image.png"/></a>
Will having many links with javascript on the webpage slow it down significantly?
Does the Javascript run when the page initially loads or only when a link is clicked?
EDIT: For those asking why I'm doing this. I'm creating an iPad site, when you use the 'add to home page' button to add the site as an icon, it allows users to view the site with no address bar.
However everytime a link is clicked it reopens Safari in a new window with the address bar back.
The only solution I could find was using javascript instead of an html based link to open the page.
For further reference see...
iPad WebApp Full Screen in Safari
2nd answer
"It only opens the first (bookmarked) page full screen. Any next page will be opened WITH the address bar visible again. Whatever meta tag you put into your page header..."
3rd answer down
"If you want to stay in a browser without launching a new window use this HTML code:
a href="javascript:this.location = 'index.php?page=1'"
"
发布评论
评论(2)
我可以看到这稍微增加了站点的带宽需求(非常轻微),但是渲染时间和点击响应时间不应该是明显的。
如果这是一个大问题,我建议对两种不同的方法进行基准测试以比较真正的影响。
I can see this adding to the bandwidth needs of a site marginally (very marginally), but the render time and the response time on clicking shouldn't be noticeable.
If it is a large concern I would recommend benchmarking the two different approaches to compare the real impact.
你说放慢速度是什么意思?
页面加载时间?取决于您页面上的链接数量。必须有很多才能引人注目。执行时间?再次,不明显。
更好的问题是,您是否愿意为那些没有 JavaScript 的用户有效删除您的网站?
此外,如果您担心搜索引擎优化,您将需要采取额外的措施来确保您的网站仍然可以被索引。 (我怀疑谷歌会遵循这些类型的网址......我猜可能是错误的)。
编辑:现在您已经解释了上面的情况,您可以轻松地“隐藏”地址栏。请参阅这个问题。
What do you mean by slow it down?
Page load time? Depends on the number of links on your page. It would have to be a LOT to be noticeable. Execution time? Again, not noticeable.
The better question to ask is are you o.k. with effectively deleting your website for those without javascript?
Also, if you are worried about SEO, you will need to take additional measures to ensure your site can still be indexed. (I doubt Google follows those kinds of URLs... could be wrong I guess).
EDIT: Now that you explained your situation above, you could easily just "hide" the address bar. See this SO question.