EL获取window open的URL中参数

本文介绍如何在JSP页面中使用EL表达式获取URL参数rid,并将其用于隐藏域元素的值设置。通过具体代码示例展示了如何实现这一功能。

window.open("http://www.4ye.cc/cart/confirm?rid=XXXXXXX")

要在jsp页面中用el获取到rid参数的值:

<input type="hidden" id="rid" value="${param.rid}">

在Vue中,默认情况下,`window.open`方法会继承当前页面的协议(HTTP或HTTPS)。如果你希望强制通过HTTP打开网页,可以通过以下几种方法实现: ### 方法一:使用绝对URL 确保在调用`window.open`时使用绝对URL,并显式指定协议为HTTP。 ```javascript window.open('http://example.com', '_blank'); ``` ### 方法二:检查当前协议并重定向 在Vue组件中,可以在调用`window.open`之前检查当前页面的协议,如果是HTTPS,则手动重定向到HTTP。 ```javascript methods: { openInHttp(url) { const currentProtocol = window.location.protocol; if (currentProtocol === 'https:') { url = url.replace(/^https:/, 'http:'); } window.open(url, '_blank'); } } ``` ### 方法三:使用Vue Router导航 如果你使用的是Vue Router,可以在导航守卫中处理协议转换。 ```javascript const router = new VueRouter({ routes: [ // your routes ], beforeEach(to, from, next) { if (window.location.protocol === 'https:') { to.fullPath = to.fullPath.replace(/^https:/, 'http:'); } next(); } }); ``` ### 方法四:使用Meta标签 在HTML的`<head>`部分添加Meta标签,指示浏览器通过HTTP打开链接。 ```html <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> ``` 不过,这种方法会影响整个页面的所有链接,不仅仅是`window.open`。 ### 方法五:自定义指令 创建一个自定义Vue指令来处理`window.open`的行为。 ```javascript Vue.directive('open-in-http', { bind(el, binding) { el.addEventListener('click', () => { let url = binding.value; if (window.location.protocol === 'https:') { url = url.replace(/^https:/, 'http:'); } window.open(url, '_blank'); }); } }); ``` 然后在模板中使用这个指令: ```html <button v-open-in-http="'http://example.com'">Open in HTTP</button> ``` 通过以上方法,你可以确保在Vue应用中,`window.open`方法始终通过HTTP打开网页。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值