How to specify referrer URI when navigating to a page in Storyboards WebView in Swift

 When navigating a Storyboards WebView to a new URI, you may want to specify a referrer URI. When using the WebView, we can do this using the load function. To use this function, we need to create a URLRequest. From a URLRequest, we can add a value for referrer to the request, then pass it into the load function of the WebView like so.

Swift:

let myURL = URL(string"https://codingguides.quinnscomputing.com")

var myRequest = URLRequest(url: myURL!)

myRequest.addValue("https://www.quinnscomputing.com", forHTTPHeaderField: "Referer")

self.WebViewMain.load(myRequest)

This will navigate the WebView to the specified URI with the specified referrer URI.


This snippet is available in Codly. Click the appropriate link below to download the snippet. If you don't have Codly, it is available here in the Microsoft Store.

Comments

Popular posts from this blog

How to enable dark title bar in Windows Forms and WPF (Windows Presentation Foundation) apps

How to enable precision scrolling in a WPF app on Windows

How to show placeholder text in a WPF textbox