我正在使用iframe -tag将Google Map嵌入我的网站。 由于它是挪威语地址,我必须使用UTF-8十六进制代码替换æ,ø,å等字符,这样可以正常工作。 但是有一些我似乎无法取代的角色。
要复制此问题,我有这个iframe :
<iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=nb&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>我正在使用这个jQuery代码来替换字符:
$(document).ready(function () { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); src = encodeURI(src); googleMap.attr('src', src); src.replace('æ', '%C3%A6'); src.replace('ø', '%C3%B8'); src.replace('å', '%C3%A5'); src.replace('é', '%C3%A9'); src.replace('Æ', '%C3%86'); src.replace('Ø', '%C3%98'); src.replace('Å', '%C3%85'); src.replace('É', '%C3%89'); // replacing is working to here src.replace('%252520', '+'); src.replace('%25252B', '+'); src.replace('%2525', '%'); });在这里你可以看到jsfiddle: https ://jsfiddle.net/oehLcevd/9/
如果使用Dev Tools检查iframe ,则可以看到iframe的src -attribute。
提前致谢!
I am using iframe-tag to embed Google Map to my website. Since it's a Norwegian address I have to replace characters like æ, ø, å and so on with UTF-8 hex-code which is working fine. But there are some characters which I can't seem to replace.
To replicate the issue I have this iframe:
<iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=nb&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>And I am using this jQuery-code to replace characters:
$(document).ready(function () { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); src = encodeURI(src); googleMap.attr('src', src); src.replace('æ', '%C3%A6'); src.replace('ø', '%C3%B8'); src.replace('å', '%C3%A5'); src.replace('é', '%C3%A9'); src.replace('Æ', '%C3%86'); src.replace('Ø', '%C3%98'); src.replace('Å', '%C3%85'); src.replace('É', '%C3%89'); // replacing is working to here src.replace('%252520', '+'); src.replace('%25252B', '+'); src.replace('%2525', '%'); });Here you can see the jsfiddle: https://jsfiddle.net/oehLcevd/9/
If you inspect the iframe with Dev Tools, you can see the src-attribute of the iframe.
Thanks in advance!
最满意答案
我能够使用JavaScript中的decodeURIComponent()函数对您的查询进行规范化。 我想知道为什么我必须调用它两次来规范化URL参数,但如果你现在检查iFrame src,它将显示你所需的答案。 希望有更好知识的人能够有所启发。
第一个控制台输出将显示原始URL,第二个将显示解码的URL。
$(document).ready(function() { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); console.log(googleMap.attr('src')); googleMap.attr('src', decodeURIComponent(decodeURIComponent(src))); console.log(googleMap.attr('src')); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Address: Lille Hunstad 4A, 8019 BODØ <br> <iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=en&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>I was able to normalized your query using decodeURIComponent() function in JavaScript. I wonder why i had to call it twice to normalize the URL parameters but if you inspect the iFrame src now it will show your required answer. Hope someone with better knowledge can shed some light.
The first console output will show the original URL and second one will illustrate the decoded URL.
$(document).ready(function() { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); console.log(googleMap.attr('src')); googleMap.attr('src', decodeURIComponent(decodeURIComponent(src))); console.log(googleMap.attr('src')); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Address: Lille Hunstad 4A, 8019 BODØ <br> <iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=en&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe> 替换Google地图中的特殊字符(Replace special characters in Google Map)我正在使用iframe -tag将Google Map嵌入我的网站。 由于它是挪威语地址,我必须使用UTF-8十六进制代码替换æ,ø,å等字符,这样可以正常工作。 但是有一些我似乎无法取代的角色。
要复制此问题,我有这个iframe :
<iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=nb&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>我正在使用这个jQuery代码来替换字符:
$(document).ready(function () { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); src = encodeURI(src); googleMap.attr('src', src); src.replace('æ', '%C3%A6'); src.replace('ø', '%C3%B8'); src.replace('å', '%C3%A5'); src.replace('é', '%C3%A9'); src.replace('Æ', '%C3%86'); src.replace('Ø', '%C3%98'); src.replace('Å', '%C3%85'); src.replace('É', '%C3%89'); // replacing is working to here src.replace('%252520', '+'); src.replace('%25252B', '+'); src.replace('%2525', '%'); });在这里你可以看到jsfiddle: https ://jsfiddle.net/oehLcevd/9/
如果使用Dev Tools检查iframe ,则可以看到iframe的src -attribute。
提前致谢!
I am using iframe-tag to embed Google Map to my website. Since it's a Norwegian address I have to replace characters like æ, ø, å and so on with UTF-8 hex-code which is working fine. But there are some characters which I can't seem to replace.
To replicate the issue I have this iframe:
<iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=nb&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>And I am using this jQuery-code to replace characters:
$(document).ready(function () { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); src = encodeURI(src); googleMap.attr('src', src); src.replace('æ', '%C3%A6'); src.replace('ø', '%C3%B8'); src.replace('å', '%C3%A5'); src.replace('é', '%C3%A9'); src.replace('Æ', '%C3%86'); src.replace('Ø', '%C3%98'); src.replace('Å', '%C3%85'); src.replace('É', '%C3%89'); // replacing is working to here src.replace('%252520', '+'); src.replace('%25252B', '+'); src.replace('%2525', '%'); });Here you can see the jsfiddle: https://jsfiddle.net/oehLcevd/9/
If you inspect the iframe with Dev Tools, you can see the src-attribute of the iframe.
Thanks in advance!
最满意答案
我能够使用JavaScript中的decodeURIComponent()函数对您的查询进行规范化。 我想知道为什么我必须调用它两次来规范化URL参数,但如果你现在检查iFrame src,它将显示你所需的答案。 希望有更好知识的人能够有所启发。
第一个控制台输出将显示原始URL,第二个将显示解码的URL。
$(document).ready(function() { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); console.log(googleMap.attr('src')); googleMap.attr('src', decodeURIComponent(decodeURIComponent(src))); console.log(googleMap.attr('src')); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Address: Lille Hunstad 4A, 8019 BODØ <br> <iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=en&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>I was able to normalized your query using decodeURIComponent() function in JavaScript. I wonder why i had to call it twice to normalize the URL parameters but if you inspect the iFrame src now it will show your required answer. Hope someone with better knowledge can shed some light.
The first console output will show the original URL and second one will illustrate the decoded URL.
$(document).ready(function() { /** REPLACE SPECIAL CHARACTERS IN GOOGLE MAPS IFRAME SRC **/ var googleMap = $('#googlemap'); var src; src = googleMap.attr('src'); console.log(googleMap.attr('src')); googleMap.attr('src', decodeURIComponent(decodeURIComponent(src))); console.log(googleMap.attr('src')); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Address: Lille Hunstad 4A, 8019 BODØ <br> <iframe id="googlemap" name="mapframe" width="425" height="350" src="https://www.google.com/maps?z=11&f=d&output=embed&language=en&q=Lille%2520Hunstad%25204A,8019%252BBOD%25C3%2598"> </iframe>
发布评论