Javascript 如何用要约墙iframe中的实际uid替换[USER_ID]
我正在制作一个GPT站点(Get Pay to),在那里人们可以因为完成报价而获得奖励,但是我在将uid添加到报价链接时遇到了问题 例如:Javascript 如何用要约墙iframe中的实际uid替换[USER_ID],javascript,php,iframe,uid,Javascript,Php,Iframe,Uid,我正在制作一个GPT站点(Get Pay to),在那里人们可以因为完成报价而获得奖励,但是我在将uid添加到报价链接时遇到了问题 例如: <iframe src="https://example.com/api/?key=xxxxxx&uid=[USER_ID]" width="500" height="900" frameborder="0"></iframe> 如何用uid=12345替换uid=[USER\u ID]? 感谢使用javascript,
<iframe src="https://example.com/api/?key=xxxxxx&uid=[USER_ID]" width="500" height="900" frameborder="0"></iframe>
如何用uid=12345
替换uid=[USER\u ID]
?
感谢使用javascript,您可以执行
str=str.replace(“[USER\u ID]”,123)代码>
其中str是包含uid=[USER\u ID]的字符串
所以字符串将是uid=12345
因此:
var str=”https://example.com/api/?key=xxxxxx&uid=[用户ID]“,
userId=12345;
document.getElementById('iframeId').src=str.replace(“[USER\u ID]”,userId);
结果会怎样
<iframe id="iframeId" src="https://example.com/api/?key=xxxxxx&uid=12345" width="500" height="900" frameborder="0">
您尝试了什么?发布你的php代码。你在哪里从javascript设置scr url,我的用户来自哪里?我想我要寻找的是如何在example.com/[user\u ID]这样的链接中替换user\u ID。请参见下面的答案,一个简单的字符串替换将完成我使用的trickI,它给了我一个注册页,几乎给了用户一个ID。这个脚本有用户的信息,但我希望能够从中提取uid添加到uid=“[user_ID]”的位置
<iframe id="iframeId" src="https://example.com/api/?key=xxxxxx&uid=12345" width="500" height="900" frameborder="0">