0

I have the following statement to get the href location of my iframe window...

var mbackwindow = document.getElementById("mframe").contentWindow.location.href;

depending on how I load the initial page, the console.log(mbackwindow) will show me either http://something/page/stuff.html, or https://something/page/stuff.html

From my variable mbackwindow, I want to get the "/page/stuff.html", no matter if the location is coming from http or https. How I collect that via javascript / jquery?

Thanks!

2 Answers 2

2

Use the following window.location property:

window.location.pathname

So in your case, use:

var mbackwindow = document.getElementById("mframe").contentWindow.location.pathname;

Reference: https://developer.mozilla.org/en-US/docs/DOM/window.location#Properties

Sign up to request clarification or add additional context in comments.

Comments

1

instead of href use pathname

document.getElementById("mframe").contentWindow.location.pathname

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.